<template>
	<view>
		<pageheader :setting="settingdata"></pageheader>
		<view class="addressbox_no" v-if="selectThe.id" @click="goaddress">
			<u-icon name="map" color="#38BE8C" size="32"></u-icon>
			<view class="addressinfo">
				<view class="addresstop">
					<text class="name">{{selectThe.username}}</text>
					<text class="phone">{{selectThe.mobile}}</text>
				</view>
				<view class="addressmain">{{selectThe.province}} {{selectThe.city}} {{selectThe.area}} {{selectThe.address}}</view>
			</view>
			<u-icon name="arrow-right" color="#999999" size="28" class="mainicon"></u-icon>
		</view>
	   <view class="addressbox_no" v-else @click="goaddress">
		  <view class="address_noleft">
			<u-icon name="map" color="#38BE8C" size="32"></u-icon>
			<text>请先添加收货地址</text>
		  </view>
		  <u-icon name="arrow-right" color="#999999" size="28" class="mainicon"></u-icon>
		</view>
		<view class="contentsbox">
			<navigator :url="'/home/station/stationpage?id='+goods.memberinfo.id" hover-class="none" class="contents_shops" v-if="goods.memberinfo.name">
				<view class="storesinfo">
					<text class="name">卖家：{{goods.memberinfo.name}}</text>
					<image :src="goods.memberinfo.mimage" v-if="goods.memberinfo.mimage" mode="heightFix"></image>
					<view class="xinyong_box">
						<view class="xin">信</view>
						<view class="xin_number">{{goods.memberinfo.credit_value}}</view>
						<view class="shiming" v-if="goods.merchant_info.realname">实</view>
						<view class="qiye" v-if="goods.memberinfo.enterprise">企</view>
					</view>
				</view>
				<u-icon name="arrow-right" color="#999999" size="28"></u-icon>
			</navigator>
			<view class="shops_details" v-if="goods.goods_info.title">
				<image :src="goods.goods_info.image" mode="aspectFill"></image>
				<view class="details_info">
					<text class="detailname clamp2">{{goods.goods_info.title}}</text>
					<view class="hot_info">
						<view class="hot_price"><text>￥</text>{{goods.goods_info.money}}<text>/{{goods.goods_info.unit}}</text></view>
						<text class="hot_looks">{{goods.goods_info.view}}人查看</text>
					</view>
					<!-- <view class="hotsku">产品规格产品规格</view> -->
				</view>
			</view>
			<view class="sureorderinfox">
				<view class="infoline">
					<view class="mainlinetext">购买数量<text>*</text></view>
					<u-number-box v-model="number" :min="minnumber" :max="1000000" :input-width="182" :size="32"
						:input-height="60" @change="setprice"></u-number-box>
				</view>
				<view class="infoline">
					<view class="mainlinetext">待议单价</view>
					<text>￥{{goods.unit_price}}</text>
				</view>
				<view class="infoline">
					<view class="mainlinetext">其他杂费</view>
					<text>￥{{goods.other_price}}</text>
				</view>
				<view class="infoline">
					<view class="mainlinetext">协商总价</view>
					<text class="total">￥{{negotiate}}</text>
				</view>
			<!-- 	<view class="infoline">
					<view class="mainlinetext">诚意金抵扣</view>
					<text>￥{{goods.money}}</text>
				</view> -->
				<view class="infoline">
					<view class="mainlinetext">尾款金额</view>
					<text v-if="total_price.length>0">￥{{total_price}}</text>
				</view>
			</view>
			<view class="mainline" @click="setdate=true">
				<view class="mainlinetext">到货时间<text>*</text></view>
				<veiw class="mainlineinput" v-if="stoptime.length>0">{{stoptime[0]}}年 {{stoptime[1]}}月 {{stoptime[2]}}日</veiw>
				<text class="mainlineinput" v-else>请选择到货时间</text>
				<u-icon name="arrow-right" color="#999999" size="24" class="mainicon"></u-icon>
			</view>
			<!-- <view class="mainline">
				<view class="mainlinetext">备注说明</view>
				<u-input v-model="client_note" type="textarea" :border="false" placeholder="请备注看货要求(50字以内)" :autoHeight="true"
					class="mainlineinput" :clearable="false" />
			</view> -->
			<view class="reminder">
				<view class="h3">温馨提示</view>
				<view class="p">
					1、备注说明请务必填写与供应方协商的详细内容，备注是重要的凭证 
				</view>
				<view class="p">
					2、若遇到其他纠纷问题，请联系平台方处理
				</view>
			</view>
		</view>
		<view class="bottomsbox">
			<view class="submitbtn" @click="submit">立即购买</view>
		</view>
		<u-picker mode="time" v-model="setdate" @confirm="getstoptime"  start-year="2021" end-year="2121"></u-picker>
	</view>
</template>

<script>
	var _this, shak;
	export default {
		data() {
			return {
				settingdata: {
					name: '立即购买',
					bgColor: '#fff',
					titleColor: '#000000',
					showNav: true,
					showTypes: 0,
					position: "limitbuy"
				},
				// 备注说明
				client_note: '',
				number: 1,
				// 选择时间
				setdate: false,
				// 选择时间
				stoptime: [],
				// 选中的地址
				selectThe:{},
				goods:{},
				// 总价
				total_price:"",
				// 最低购买数量
				minnumber:0,
				// 协商总价
				negotiate:0
			}
		},
		onLoad(e) {
			_this = this
			_this.id = e.id
			_this.getdata()
			_this.getaddress()
		},
		onShow() {
			if(uni.getStorageSync("selectThe")){
				_this.selectThe=uni.getStorageSync("selectThe")
				uni.removeStorageSync("selectThe")
			}
		},
		methods: {
			// 获取数据
			getdata() {
				_this.$api.get("confirmorder", {
					order_id: _this.id,
					tab_type:2
				}).then(data => {
					_this.goods = data
					_this.number=data.number
					_this.minnumber=data.number
					_this.total_price=_this.$plug.jia(_this.$plug.jian(_this.$plug.cheng(data.unit_price,data.number),data.money),data.other_price)
					_this.negotiate=_this.$plug.jia(_this.$plug.cheng(data.unit_price,data.number),data.other_price)
				});
			},
			// 获取数据
			getaddress() {
				_this.$api.get("getaddress", {}).then(data => {
					_this.selectThe = data[0]
				});
			},
			//设置求购结束时间
			getstoptime(e) {
				_this.stoptime = [e.year, e.month, e.day]
				_this.setdate = false
			},
			// 防抖点击
			click_shake(fn){
				if(!_this.shake){
					fn && typeof fn === 'function' && fn()
					_this.shake=true
					setTimeout(function(){
						_this.shake=false
					},500)
				}
			},
			submit: function() {
				_this.click_shake(function(){
					let data = [ {
							value: _this.selectThe,
							type: 1,
							title: "请填写收货地址"
						},{
							value: _this.stoptime.length,
							type: 2,
							title: "请选择到货时间"
						}
					]
					if (_this.$plug.verify(data)) {
						uni.navigateTo({
							url:"lookPay?number="+_this.number+"&order_id="+_this.id+"&arrivaltime="+_this.stoptime.join('-')+"&city_id="+_this.selectThe.id+"&money="+_this.total_price
						})
					}
				})
			},
			goaddress(){
				_this.click_shake(()=>{
					uni.navigateTo({
						url:"/personal/myAddress?place_order=1"
					})
				})
			},
			setprice(e){
				_this.total_price=_this.$plug.jia(_this.$plug.jian(_this.$plug.cheng(_this.goods.unit_price,e.value),_this.goods.money),_this.goods.other_price)
				_this.negotiate=_this.$plug.jia(_this.$plug.cheng(_this.goods.unit_price,e.value),_this.goods.other_price)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.addressbox_no {
		padding: 45rpx 30rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		border-bottom: 8rpx solid #F2F2F2;

		.address_noleft {
			display: flex;
			flex-direction: row;
			align-items: center;

			text {
				margin-left: 18rpx;
				color: #999999;
				font-size: 30rpx;
			}
		}

		.addressinfo {
			margin-left: 20rpx;
			flex: 1;
			display: flex;
			flex-direction: column;

			.addresstop {
				display: flex;
				flex-direction: row;
				align-items: flex-end;

				.name {
					color: #333333;
					font-size: 32rpx;
				}

				.phone {
					color: #333333;
					font-size: 28rpx;
					margin-left: 21rpx;
				}
			}

			.addressmain {
				margin-top: 20rpx;
				color: #999999;
				font-size: 26rpx;
			}
		}
	}

	.contentsbox {
		margin: 0 25rpx;
		padding-bottom: 110rpx;
		padding-bottom: calc(env(safe-area-inset-bottom) + 110rpx);
		display: flex;
		flex-direction: column;
		background-color: #fff;

		.contents_shops {
			padding: 40rpx 0 30rpx 0;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;
			border-bottom: 2rpx solid #E6E6E6;

			.storesinfo {
				display: flex;
				flex-direction: row;
				align-items: center;

				.name {
					color: #333333;
					font-size: 32rpx;
					font-weight: bold;
				}

				image {
					width: auto;
					height: 36rpx;
					margin-left: 22rpx;
				}

				.xinyong_box {
					display: flex;
					flex-direction: row;
					align-items: center;
					margin-left: 8rpx;

					.xin {
						width: 30rpx;
						height: 30rpx;
						background: #00C575;
						border-radius: 3px 0 0 3rpx;
						text-align: center;
						line-height: 30rpx;
						color: #fff;
						font-size: 20rpx;
					}

					.xin_number {
						background-color: #fff;
						border: 2rpx solid #00C575;
						border-radius: 0 3rpx 3rpx 0;
						color: #00C575;
						font-size: 20rpx;
						text-align: center;
						height: 30rpx;
						line-height: 30rpx;
						min-width: 46rpx;
					}
				}
			}
		}

		.shops_details {
			display: flex;
			flex-direction: row;
			padding: 27rpx 0;

			image {
				width: 180rpx;
				height: 180rpx;
				border-radius: 5rpx;
			}

			.details_info {
				width: 460rpx;
				display: flex;
				flex-direction: column;
				margin-left: 24rpx;

				.detailname {
					color: #222222;
					font-size: 30rpx;
					line-height: 40rpx;
					height: 80rpx;
				}

				.hot_info {
					margin-top: 25rpx;
					display: flex;
					flex-direction: row;
					align-items: center;

					.hot_price {
						font-size: 30rpx;
						color: #F73F3F;
						font-weight: bold;
						display: flex;
						flex-direction: row;
						align-items: flex-end;

						text {
							font-weight: normal;
							font-size: 24rpx;
						}
					}

					.hot_looks {
						font-size: 22rpx;
						color: #999999;
						margin-left: 17rpx;
					}
				}

				.hotsku {
					margin-top: 25rpx;
					color: #999999;
					font-size: 22rpx;
				}
			}
		}

		.sureorderinfox {
			padding-bottom: 56rpx;
			border-bottom: 2rpx solid #E6E6E6;
			display: flex;
			flex-direction: column;

			.infoline {
				display: flex;
				flex-direction: row;
				align-items: center;
				margin-top: 52rpx;
				justify-content: space-between;

				.mainlinetext {
					color: #333333;
					font-size: 30rpx;
					font-weight: bold;

					text {
						color: #FF0000;
					}
				}

				text {
					color: #333333;
					font-size: 30rpx;
				}

				.total {
					color: #38BE8C;
					font-size: 32rpx;
					text-align: right;
				}
			}
		}

		.mainline {
			display: flex;
			flex-direction: row;
			margin-top: 52rpx;

			.mainlinetext {
				color: #333333;
				font-size: 30rpx;
				font-weight: bold;

				text {
					color: #FF0000;
				}
			}

			.steps_ {
				margin-left: 74rpx;
			}

			.mainlineinput {
				margin-left: 74rpx;
				flex: 1;
				font: 30rpx;
				color: #333333;
			}

			.sysmol {
				margin-left: 20rpx;
				color: #333333;
				font-size: 30rpx;
			}

			.mainlineposition {
				margin-left: 76rpx;
				color: #333333;
				font-size: 30rpx;
				flex: 1;
			}

			.mainicon {
				margin-left: 20rpx;
			}
		}
	}

	.bottomsbox {
		height: 110rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #fff;
		position: fixed;
		bottom: 0;
		width: 100%;
		padding-bottom: calc(env(safe-area-inset-bottom));
		z-index: 99;

		.submitbtn {
			width: 680rpx;
			height: 90rpx;
			background: linear-gradient(86deg, #38BE8C, #05ADBB);
			border-radius: 45rpx;
			text-align: center;
			color: #fff;
			font-size: 34rpx;
			font-weight: bold;
			line-height: 90rpx;
		}
	}
	.reminder{
		margin-top: 60rpx;
		.h3{
			font-size: 30rpx;
			margin-bottom: 20rpx;
		}
		.p{
			font-size: 24rpx;
			margin-bottom: 10rpx;
		}
	}
</style>
